package com.guigu.eduservice.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.guigu.eduservice.entity.BargainIntention;
import com.guigu.eduservice.service.BargainIntentionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/advertisement/bargainintention")
public class BargainIntentionController {
    @Autowired
    BargainIntentionService bargainIntentionService;
    //添加砍价意向
    @PostMapping("/addBargainIntention")
    public String addBargainIntention(@RequestBody BargainIntention bargainIntention){
        bargainIntention.setBargainStatus(0);
        boolean save = bargainIntentionService.save(bargainIntention);
        if (save){
            return "添加成功";
        }else {
            return "添加失败";
        }
    }
//查询是否存在
    @ResponseBody
    @PostMapping("/isBargainIntention")
    public String isBargainIntention(@RequestBody BargainIntention bargainIntention){

        QueryWrapper<BargainIntention> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id",bargainIntention.getUserId());
        queryWrapper.eq("equipment_id",bargainIntention.getEquipmentId());
        boolean isBargainIntention = bargainIntentionService.getOne(queryWrapper) != null;
        if (isBargainIntention){
            System.out.println("已砍");
            return "已砍";
        }else {
            System.out.println("砍价");
            return "砍价";
        }
    }
}
